package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.OrderDetail;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api("订单管理接口")
@Slf4j
@RestController("adminOrdersController")
@RequestMapping("/admin/order")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 取消订单
     * @param dto
     * @return
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancelOrder(@RequestBody OrdersCancelDTO dto){
        ordersService.cancelOrders(dto);
        return Result.success();
    }

    /**
     * 完成订单
     * @param id
     * @return
     */
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id){
        ordersService.complete(id);
        return Result.success();
    }

    /**
     * 派送订单
     * @param id
     * @return
     */
    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    private Result delivery(@PathVariable Long id){
        ordersService.delivery(id);
        return Result.success();
    }

    /**
     * 拒单
     * @param dto
     * @return
     */
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO dto){
        ordersService.rejection(dto);
        return Result.success();
    }

    /**
     * 接单
     * @param dto
     * @return
     */
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO dto){
        ordersService.confirm(dto);
        return Result.success();
    }

    @ApiOperation("查询订单详情")
    @GetMapping("/details/{id}")
    public Result getOrder(@PathVariable Long id){
        OrderVO vo = ordersService.getOrder(id);
        return Result.success(vo);
    }

    /**
     * 各个状态的订单数量统计
     * @return
     */
    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result getStatistics(){
        OrderStatisticsVO vo = ordersService.getStatistics();
        return Result.success(vo);
    }

    /**
     * 订单搜索
     * @param dto
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result searchOrder(OrdersPageQueryDTO dto){
        PageResult pageResult = ordersService.searchOrder(dto);
        return Result.success(pageResult);
    }
}
